package com.bjesc_b2c.app.appraiset.mvp.model.impl;

import android.content.Context;

import com.bjesc_b2c.app.appraiset.http.IApiFragmentRequest;
import com.bjesc_b2c.app.appraiset.mvp.model.CarDetailsModel;
import com.bjesc_b2c.app.appraiset.utils.CustomSharedPreferences;
import com.rxretrofit_build.util.MapUtil;

import java.util.HashMap;

import master_bean.CarDetailsBean;
import rxretrofit_base.model.KeyBean;
import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;


/**
 * Created by yidong on 2017/5/18.
 */

public class CarDetailsModelImpl implements CarDetailsModel {

    private DeteilsCallBack callBack;
    public CarDetailsModelImpl(DeteilsCallBack callBack){
        this.callBack = callBack;
    }
    @Override
    public void getCarDetails(Context context) {
        HashMap<String, Object> build = new MapUtil()
                .put("car_id", CustomSharedPreferences.getString(context, KeyBean.CARID.valueOf(), KeyBean.FILE_NAME.valueOf()))
                .build();
        RxRequest.request(ShowType.SHOW, RxRequest.getClient(context, build).create(IApiFragmentRequest.class).getCarDeteils()
                , new BaseSubscriber<TokenBean<CarDetailsBean>>(context) {
                    @Override
                    public void onSuccess(TokenBean<CarDetailsBean> o) {
                        if(o.getData()!= null ) {
                            if(callBack!=null){
                                callBack.datecallBack(o.getData());
                            }
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {

                    }
                });

    }

   public interface DeteilsCallBack{
       void datecallBack(CarDetailsBean carBean);
   }
}
